using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ApPaydetMap : EntityTypeConfiguration<ApPaydet>
    {
        public ApPaydetMap()
        {
            // Primary Key
            this.HasKey(t => t.APPAYDET_ID);

            // Properties
            this.Property(t => t.PAYREF)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.APREF)
                .HasMaxLength(6);

            this.Property(t => t.INVNO)
                .HasMaxLength(8);

            this.Property(t => t.VOUCH_DESC)
                .HasMaxLength(100);

            this.Property(t => t.ACCT)
                .HasMaxLength(40);

            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("ApPaydet");
            this.Property(t => t.APPAYDET_ID).HasColumnName("APPAYDET_ID");
            this.Property(t => t.PAYREF).HasColumnName("PAYREF");
            this.Property(t => t.APREF).HasColumnName("APREF");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.MPDTODAY).HasColumnName("MPDTODAY");
            this.Property(t => t.MPDTODAYD).HasColumnName("MPDTODAYD");
            this.Property(t => t.DISCOUNT).HasColumnName("DISCOUNT");
            this.Property(t => t.DISCOUNTD).HasColumnName("DISCOUNTD");
            this.Property(t => t.VOUCH_DESC).HasColumnName("VOUCH_DESC");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.MPDTODAYA).HasColumnName("MPDTODAYA");
            this.Property(t => t.DISCOUNTA).HasColumnName("DISCOUNTA");
            this.Property(t => t.ACCT).HasColumnName("ACCT");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasOptional(t => t.Acct1)
                .WithMany(t => t.ApPaydets)
                .HasForeignKey(d => d.ACCT);
            this.HasRequired(t => t.ApPymt)
                .WithMany(t => t.ApPaydets)
                .HasForeignKey(d => d.PAYREF);
            this.HasRequired(t => t.Batchttl)
                .WithMany(t => t.ApPaydets)
                .HasForeignKey(d => d.BATCH);
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.ApPaydets)
                .HasForeignKey(d => d.CSTCTRID);

        }
    }
}
